Skip to content

Add PUT /users/:id (update a user) - #28

Open
franzyellow wants to merge 4 commits into
mate-academy:mainfrom
franzyellow:feature/update-user-endpoint
Open

Add PUT /users/:id (update a user)#28
franzyellow wants to merge 4 commits into
mate-academy:mainfrom
franzyellow:feature/update-user-endpoint

Conversation

@franzyellow

Copy link
Copy Markdown

Summary

  • Adds PUT /users/:id to update an existing user's name/email, following the existing GET/POST route patterns
  • Adds updateUser(id, { name, email }) to db/store.js as the data-access helper for the new route
  • Validates the body before touching the store (!name || !email → 400), and returns 404 when the id doesn't exist, rather than crashing
  • Adds NOTES.md documenting the plan, model choice (Sonnet), commit split, and what self-review caught

Why

This is the course's "ship a real change end to end" exercise — implementing the update-user endpoint that tests/update-user.test.js already specifies, without editing that test file.

What to test

  • npm test — all 9 tests pass, including the three update-user.test.js cases and the two NOTES.md checks
  • PUT /users/:id with a full valid body on an existing id → 200 with the updated user
  • PUT /users/:id on a nonexistent id → 404, not a crash
  • PUT /users/:id with a missing field (e.g. only name) → 400

🤖 Generated with Claude Code

Yunchong Huang added 4 commits July 9, 2026 14:46
Mirrors getUserById's lookup and createUser's destructured params.
Mutates in place and returns undefined when the id doesn't exist,
so callers can reuse the existing !user not-found check.
Validates name/email before touching the store, same order as POST,
so a bad body reports 400 even when the target id doesn't exist.
Returns 404 via store.updateUser's undefined sentinel otherwise.
Self-review caught updateUser re-implementing the same id lookup
getUserById already does, risking drift if the lookup logic changes.
Explains the approved plan, model choice, commit split, and what
self-review caught, per the assignment's deliverables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant